package com.candy.actiivemq.jms;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * @author: candy
 * @date: 2020/9/20
 * @description :
 **/
@Slf4j
public class CandyMessageListener implements MessageListener {

    @SneakyThrows
    @Override
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            TextMessage messages = (TextMessage) message;
            log.info("监听器收到消息 : {}",  messages.getText());
        }

        if (message instanceof MapMessage) {
            MapMessage messages = (MapMessage) message;
            String k1 = messages.getString("k1");
            String k2 = messages.getString("k2");
            log.info("Map message k1: {} \t k2 :{}", k1, k2);
        }
    }
}
